package com.v.im.websocketservice.config;

import com.v.im.commonmodule.utils.zkclient.balance.client.LoadBalanceImplProvider;
import com.v.im.commonmodule.utils.zkclient.balance.constans.ZkConstant;
import com.v.im.commonmodule.utils.zkclient.balance.server.RegistAndUnregistOperator;
import com.v.im.commonmodule.utils.zkclient.balance.server.ServerData;
import lombok.extern.slf4j.Slf4j;
import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.serialize.SerializableSerializer;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.zookeeper.ZookeeperProperties;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ZkConnectConfig {

    @Autowired
    private ZookeeperProperties zookeeperProperties;

    /**
     * 获取zk 连接地址
     */

    public LoadBalanceImplProvider<ServerData> getBalanceProvider() {
        String connectAddress = zookeeperProperties.getConnectString();
        if (StringUtils.isBlank(connectAddress)) {
            log.error(" 获取zookeeper连接地址为空！！！");
        }
        return new LoadBalanceImplProvider<>(connectAddress, ZkConstant.SERVERS_NODE_PATH);
    }
}
